<template>
  <Table
    row-key="id"
    :loading="loading"
    :columns="columns"
    :data="data"
    border
  ></Table>
</template>
<script>
import * as API_Member from "@/api/member.js";
import gradeMixins from "../mixins/gradeData";
export default {
  mixins: [gradeMixins],
  data() {
    return {
      loading: false, // 加载状态
      data: [], // 表格数据
      columns: [
        {
          title: "会员名称",
          key: "username",
          tree: true,
        },
        {
          title: "会员昵称",
          key: "nickName",
        },
        {
          title: "会员等级",
          key: "gradeName",
        },
      ],
    };
  },
  props: {
    memberId: {
      type: String,
    },
  },
  methods: {
    loop(data) {
      data.forEach((v) => {
        v.gradeName = this.gradeLevels[v.gradeId];
        if (v.children) {
          this.loop(v.children);
        }
      });
    },
    getList(id, callback) {
      API_Member.getDirectByMember({
        memberId: id,
      }).then((res) => {
        const data = res.result;
        this.loop(data);
        this.loading = false;
        this.data = data;
        callback && callback(data);
      });
    },
    reload() {
        this.loading = true;
        this.getList(this.memberId);
    }
  },
  watch: {
    memberId: {
      handler(e) {
        if (e) {
          // this.loading = true;
          // this.getList(e);
        }
      },
      immediate: true,
    },
  },
};
</script>
